//
//  ChatFrame.m
//  AILove
//
//  Created by Ace Portgas on 2024/1/7.
//

#import "ChatFrame.h"
#import "ChatModel.h"
@implementation ChatFrame
-(void)setModel:(ChatModel *)model{
    _model = model;
    CGFloat maxWidth = SCREEN_WIDETH - 61 - 74 - 32;
    CGSize textSize = [model.content getSizeWithMaxSize:CGSizeMake(maxWidth, MAXFLOAT) andFont:[UIFont fontWithName:@"PingFangSC-Medium" size:14]];
    CGFloat textHeight = textSize.height > 24 ? textSize.height : 24;
    _contentFrame = CGRectMake(16, 8, textSize.width, textHeight);
    if (model.sendType == 1) {
        CGFloat voiceY;
        CGFloat voiceH;
        CGFloat avatarY;
        CGFloat lottieH = 40;
        CGFloat lottieW = lottieH / 105 * 144;
        if (model.voiceUrl) {
            voiceY = 12;
            voiceH = 28;
            avatarY = voiceY / 2 + voiceH;
            _voiceFrame = CGRectMake(61, voiceY, 60, voiceH);
        }else{
            voiceY = 12;
            voiceH = 0;
            avatarY = voiceY;
            _voiceFrame = CGRectMake(0, voiceY, 0, voiceH);
        }
        if (model.content.length == 0) {
            _lottieFrame = CGRectMake(0, 0, lottieW, lottieH);
        }else{
            _lottieFrame = CGRectMake(0, 0, 0, 0);
        }
        CGFloat contentW = lottieW > _contentFrame.size.width + 32 ? lottieW : _contentFrame.size.width + 32;
        CGFloat contentH = lottieH > textHeight + 16 ? lottieH : textHeight + 16;
        _avatarFrame = CGRectMake(15, avatarY, 38, 38);
        _contentBackFrame = CGRectMake(61, avatarY, contentW, contentH);
        _cellHeight = _contentBackFrame.origin.y + _contentBackFrame.size.height + 12;
    }else{
        _voiceFrame = CGRectMake(0, 0, 0, 0);
        _avatarFrame = CGRectMake(0, 0, 0, 0);
        _lottieFrame = CGRectMake(0, 0, 0, 0);
        CGFloat contentX = SCREEN_WIDETH - textSize.width - 15 - 32;
        _contentBackFrame = CGRectMake(contentX, 12, textSize.width + 32, textHeight + 16);
        _cellHeight = _contentBackFrame.origin.y + _contentBackFrame.size.height + 12;
    }
}

@end
